const { sequelize } = require('../config/database');

async function updateParticipantTable() {
  try {
    console.log('开始更新parkpart_activity_participants表结构...');
    
    // 添加联系方式和昵称字段
    await sequelize.getQueryInterface().addColumn(
      'parkpart_activity_participants',
      'contactInfo',
      {
        type: sequelize.Sequelize.STRING(255),
        allowNull: true,
        comment: '参与者的联系方式'
      }
    );
    
    await sequelize.getQueryInterface().addColumn(
      'parkpart_activity_participants',
      'joinNickname',
      {
        type: sequelize.Sequelize.STRING(50),
        allowNull: true,
        comment: '参与者加入活动时使用的昵称'
      }
    );
    
    console.log('成功添加联系方式和昵称字段');
    
    // 添加索引以提高查询性能
    await sequelize.getQueryInterface().addIndex(
      'parkpart_activity_participants',
      ['contactInfo'],
      {
        name: 'idx_participants_contact'
      }
    );
    
    await sequelize.getQueryInterface().addIndex(
      'parkpart_activity_participants',
      ['joinNickname'],
      {
        name: 'idx_participants_nickname'
      }
    );
    
    console.log('成功添加索引');
    console.log('parkpart_activity_participants表结构更新完成');
    
  } catch (error) {
    console.error('更新表结构时出错:', error);
  } finally {
    await sequelize.close();
  }
}

updateParticipantTable();